﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using DG.Tweening;

namespace Client
{
    /// <summary>
    /// UI触摸效果表现
    /// </summary>
    public class UITouchEffect : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
    {
        /// <summary>
        /// 触摸音效
        /// </summary>
        [SerializeField]
        private string TouchDownSound = "TouchDownSound";

        /// <summary>
        /// 目标
        /// </summary>
        [SerializeField]
        private Transform target;

        [SerializeField]
        private Vector3 scale = new Vector3(0.9f, 0.9f, 0.9f);
        [SerializeField]
        private float duration = 0.2f;

        private Vector3 oriScale;

        void Awake()
        {
            if (target == null)
            {
                target = transform;
            }
            oriScale = target.localScale;
        }

        public void OnPointerDown(PointerEventData eventData)
        {
            if (scale != oriScale)
            {
                target.DOScale(scale, duration);
            }

            if (!string.IsNullOrEmpty(TouchDownSound))
            {
            }
        }

        public void OnPointerUp(PointerEventData eventData)
        {
            if (scale != oriScale)
            {
                target.DOScale(oriScale, duration);
            }
        }
    }
}
